package com.xuetang9.t9.xinhuaxia.mappers;

import com.xuetang9.t9.xinhuaxia.beans.SocialChat;
import org.apache.ibatis.annotations.*;
import tk.mybatis.mapper.common.Mapper;

import java.util.List;

public interface SocialChatMapper extends Mapper<SocialChat> {

    @Select("SELECT ifnull(count(*),0) FROM social_chat WHERE p_id=#{p_id}")
    @ResultType(Integer.class)
    int getChatCountByPid(@Param("p_id")int p_id);

    @Select("select * from social_chat where p_id=#{p_id}")
    @Results({
            @Result(property = "user",column = "p_userid",one =
            @One(select = "com.xuetang9.t9.xinhuaxia.mappers.UserMapper.selectByPrimaryKey")),
            @Result(property = "chat",column = "p_chatid",one =
            @One(select = "com.xuetang9.t9.xinhuaxia.mappers.ChatMapper.queryAllbyPchatid")),
            @Result(property = "pId",column = "p_id"),
    })
    List<SocialChat> queryBypid(@Param("p_id") Integer pid);

    @Insert("insert into social_chat values(#{pId},#{pUserid},#{pChatid})")
    @SelectKey(keyColumn = "p_chatid",keyProperty = "pChatid",before = false,resultType = Integer.class,statement = "select last_insert_id()")
    int save(SocialChat socialChat);

}